package com.headwind.logistics.system.service.impl;

import com.headwind.logistics.common.pojo.Customer;
import com.headwind.logistics.common.pojo.Employee;
import com.headwind.logistics.system.dto.WorkOrderEmployeeUseDto;
import com.headwind.logistics.system.mapper.WorkOrderMapper;
import com.headwind.logistics.system.pojo.WorkOrder;
import com.headwind.logistics.system.service.intl.WorkOrderServiceIntl;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author 桂祥宇
 * @Date 2020/7/26 0026 15:10
 * @Version 1.0
 * @DESCRIPTION 工单务逻辑层实现类
 */
@Service
public class WorkOrderServiceImpl implements WorkOrderServiceIntl {

    //访问工单数据访问层
    @Resource
    private WorkOrderMapper workOrderMapper;

    /**
     * 查询所有工单
     * @param page 页码
     * @param rows 行数
     * @return
     */
    @Override
    public List<WorkOrderEmployeeUseDto> queryAllWorkOrderEmployeeUseDto(@Param("page")Integer page, @Param("rows")Integer rows){
    if (page != null){
            page = (page-1)*rows;
        }
        return workOrderMapper.queryAllWorkOrderEmployeeUseDto(page,rows);
    }

    /**
     * 根据id删除工单
     * @param workOrderId 工单id
     * @return
     */
    @Override
    public int deleteWorkOrder(int workOrderId){
        int count =workOrderMapper.deleteWorkOrder(workOrderId);
        return count;
    }


    /**
     * 根据id查询客户姓名和电话号码
     * @param id 客户id
     * @return
     */
    @Override
    public Customer queryAllCustomerid(int id){
        Customer customer=workOrderMapper.queryAllCustomerid(id);
        return customer;
    }


    /**
     * 新增工单
     * @param workOrder 工单对象
     * @return
     */
    @Override
    public int addWorkOrder(WorkOrder workOrder){

        int count =workOrderMapper.addWorkOrder(workOrder);

        return count;
    }

    /**
     * 查询所有员工号和员工名字
     * @return
     */
    @Override
    public List<Employee> queryAllEmployees(){
        List<Employee> employee =workOrderMapper.queryAllEmployees();
        return employee;
    }

    /**
     * 修改工单
     * @param workOrder
     * @return
     */
    @Override
    public int updateWorkOrder(WorkOrder workOrder){
        int count =workOrderMapper.updateWorkOrder(workOrder);
        return count;
    }
}
